capture log close

* program:	replicate_EPSR_intra-party_conflict.do
* task:		replication of "When do voters perceive intra-party conflict?
*							A democratic life cycle perspective"
* project:	disunity
* authors:	tristan klingelhöfer & jochen müller, 16.08.2023

version 18
clear all
macro drop _all



*global folder = "..."
* Please enter the folder where the data is located.
* Please note that figures and tables will be saved in the same folder.



/*
	Approach

	I.		ANALYSIS: perceptions of intra-party conflict (Politbarometer data)	
	
	II.		DESCRIPTION
	
	III. 	TABLES & FIGURES
*/



use "$folder\EPSR_intra-party_conflict_data.dta"


* Transformation
* (To allow for comparisons of the coefficients, values of both variables reflect the number of days divided by 360.)
gen prox_BTW_transformed = prox_BTW / 360
label variable prox_BTW_transformed "Proximity to BTW (days/360)"



* I. 	ANALYSIS: perceptions of intra-party conflict (Politbarometer data)
logit disunity1_B ///
	LR_dist_SD ///
	partei_afd_B partei_cdu_B partei_fdp_B partei_gru_B partei_pds_B ///
	i.zanr_num#region_num ///
		, vce(cluster befragtennummer)	
est store m1
estat ic


logit disunity1_B ///
	regierungsbeteiligung_B ///
	partei_afd_B partei_cdu_B partei_fdp_B partei_gru_B partei_pds_B ///
	i.zanr_num#region_num ///
		, vce(cluster befragtennummer)	
est store m2
estat ic


logit disunity1_B ///
	prox_BTW_transformed ///
	partei_afd_B partei_cdu_B partei_fdp_B partei_gru_B partei_pds_B ///
	i.zanr_num#region_num ///
		, vce(cluster befragtennummer)	
est store m3
estat ic


logit disunity1_B ///
	share_lost_elections ///
	partei_afd_B partei_cdu_B partei_fdp_B partei_gru_B partei_pds_B ///
	i.zanr_num#region_num ///
		, vce(cluster befragtennummer)	
est store m4
estat ic


logit disunity1_B ///
	LR_dist_SD regierungsbeteiligung_B prox_BTW_transformed share_lost_elections ///
	partei_afd_B partei_cdu_B partei_fdp_B partei_gru_B partei_pds_B ///
	i.zanr_num#region_num ///
		, vce(cluster befragtennummer)	
est store m5
estat ic


logit disunity1_B ///
	c.LR_dist_SD##parteineigung1_B ///
	regierungsbeteiligung_B prox_BTW share_lost_elections ///
	partei_afd_B partei_cdu_B partei_fdp_B partei_gru_B partei_pds_B ///
	i.zanr_num#region_num ///
		, vce(cluster befragtennummer)	
est store m6
estat ic


logit disunity1_B ///
	regierungsbeteiligung_B##parteineigung1_B ///
	LR_dist_SD prox_BTW share_lost_elections ///
	partei_afd_B partei_cdu_B partei_fdp_B partei_gru_B partei_pds_B ///
	i.zanr_num#region_num ///
		, vce(cluster befragtennummer)	
est store m7
estat ic
estat classification


logit disunity1_B ///
	c.prox_BTW##parteineigung1_B ///
	LR_dist_SD regierungsbeteiligung_B share_lost_elections ///
	partei_afd_B partei_cdu_B partei_fdp_B partei_gru_B partei_pds_B ///
	i.zanr_num#region_num ///
		, vce(cluster befragtennummer)	
est store m8
estat ic


logit disunity1_B ///
	c.share_lost_elections##parteineigung1_B ///
	LR_dist_SD regierungsbeteiligung_B prox_BTW ///
	partei_afd_B partei_cdu_B partei_fdp_B partei_gru_B partei_pds_B ///
	i.zanr_num#region_num ///
		, vce(cluster befragtennummer)	
est store m9
estat ic



* II.	DESCRIPTION
* This only includes observations that are included in regression model m5.

est restore m5

bysort befragtennummer: gen graph_ID_temp = e(sample)

* Summary statistics
tabstat disunity1_B LR_dist_SD regierungsbeteiligung_B prox_BTW share_lost_elections parteineigung1_B partei_afd_B partei_cdu_B partei_fdp_B partei_gru_B partei_pds_B ///
	if e(sample) == 1 ///
		, stat(mean median sd min max) ///
			col(stat) format(%8.2f)


bysort graph_ID_temp befragtennummer: gen graph_ID = 1 ///
	if _n == 1 & graph_ID_temp == 1

gen graph_gov = .
replace graph_gov = 1 ///
	if date > mdy(9,27,1998) & date < mdy(9,18,2005)
replace graph_gov = 2 ///
	if ((date > mdy(9,18,2005) & date < mdy(9,27,2009)) | (date > mdy(9,22,2013) & date < .))
replace graph_gov = 3 ///
	if date > mdy(9,27,2009) & date < mdy(9,22,2013)

label define lab_coalition ///
	1 "SPD-Greens" ///
	2 "CDU/CSU-SPD" ///
	3 "CDU/CSU-FDP"
label values graph_gov lab_coalition

qui sum date if graph_ID == 1
local graph_date_min1 = r(min)
local graph_date_min2 = r(min) - 100
local graph_date_max1 = r(max)
local graph_date_max2 = r(min) + 100

format date %tdDD/NN/YY

twoway ///
	(hist date ///
		if graph_ID == 1 & graph_gov == 1 ///
			, discrete freq ///
				barwidth(2) ///
				bcolor(gs0) ///
				xscale(range(`graph_date_min2' `graph_date_max2')) ///
				tlabel(`graph_date_min1' `graph_date_max1') ///
				xtitle("")) ///
	(hist date ///
		if graph_ID == 1 & graph_gov == 2 ///
			, discrete freq ///
				barwidth(2) ///
				bcolor(gs12) ///
				xscale(range(`graph_date_min2' `graph_date_max2')) ///
				tlabel(`graph_date_min1' `graph_date_max1') ///
				xtitle("")) ///
	(hist date ///
		if graph_ID == 1 & graph_gov == 3 ///
			, discrete freq ///
				barwidth(2) ///
				bcolor(gs6) ///
				xscale(range(`graph_date_min2' `graph_date_max2')) ///
				tlabel(`graph_date_min1' `graph_date_max1') ///
				ytitle("Number of respondents") ///
				xtitle("Governing parties")) ///
	, legend(order(1 "SPD-Greens" 2 "CDU/CSU-SPD" 3 "CDU/CSU-FDP") rows(1) position(6))
graph export "$folder\EPSR_intra-party_conflict_Figure3.png", as(png) name("Graph") replace



* III. TABLES & FIGURES
esttab m1 m2 m3 m4 m5 using "$folder\EPSR_intra-party_conflict_Table1.rtf" , replace ///
	abs b(2) se(2) ///
	star(* 0.01 ** 0.001) ///
	nonumbers ///
	scalars("ll Log likelihood") ///
	aic(%8.0f) pr2(%8.3f) ///
	noconstant ///
	coeflabels(_cons "Constant" ///
		disunity1_B "Disunity" ///
		LR_dist_SD "Position variance" ///
		regierungsbeteiligung_B "National government participation" ///
		prox_BTW "Distance to election1" ///
		share_lost_elections "Share lost elections" ///
		partei_afd_B "AfD" ///
		partei_cdu_B "CDU" ///
		partei_fdp_B "FDP" ///
		partei_gru_B "The Greens" ///
		partei_pds_B "PDS/The Left") ///
	nonotes addnotes("Notes: Coefficients from logistic regression models with standard errors clustered by respondent in parentheses. The dependent variable reflects the internal conflict perception that individual respondents have of the political party they are asked to evaluate. Dummy variables for surveys and West/East Germany included but not shown. Statistical significance: * p < 0.01, ** p < 0.001.") ///
	mtitles("Model 1" "Model 2" "Model 3" "Model 4" "Model 5") ///
	title("Table 1: Determinants of voters' disunity perception of political parties I")

esttab m6 m7 m8 m9 using "$folder\EPSR_intra-party_conflict_TableA81.rtf" , replace ///
	abs b(2) se(2) ///
	star(* 0.01 ** 0.001) ///
	nonumbers ///
	scalars("ll Log likelihood") ///
	aic(%8.0f) pr2(%8.3f) ///
	noconstant ///
	coeflabels(_cons "Constant" ///
		parteineigung1_B "Party identification" ///
		disunity1_B "Disunity" ///
		LR_dist_SD "Position variance" ///
		regierungsbeteiligung_B "National government participation" ///
		prox_BTW "Distance to election" ///
		share_lost_elections "Share lost elections" ///
		partei_afd_B "AfD" ///
		partei_cdu_B "CDU" ///
		partei_fdp_B "FDP" ///
		partei_gru_B "The Greens" ///
		partei_pds_B "PDS/The Left") ///
	nonotes addnotes("Notes: Coefficients from logistic regression models with standard errors clustered by respondent in parentheses. The dependent variable reflects the internal conflict perception that individual respondents have of the political party they are asked to evaluate. Dummy variables for surveys and West/East Germany included but not shown. Statistical significance: * p < 0.01, ** p < 0.001.") ///
	mtitles("Model 1" "Model 2" "Model 3" "Model 4") ///
	title("Table 2: Determinants of voters' disunity perception of political parties II")

	

* Interaktion LR_dist_SD parteineigung1_B
est restore m6

su LR_dist_SD /// 
	if e(sample) == 1
local plot_LR_dist_min = r(min)
local plot_LR_dist_max = r(max)

gen rug_where = 0.02
gen rug_pipe = "|"
gen rug_sample = e(sample)
replace rug_pipe = "" ///
	if rug_sample == 0
sort rug_sample LR_dist_SD
replace rug_pipe = "" ///
	if LR_dist_SD == LR_dist_SD[_n-1]

margins parteineigung1_B, at(LR_dist_SD=(`plot_LR_dist_min'(0.2)`plot_LR_dist_max' `plot_LR_dist_max'))

marginsplot ///
	, xdimension(LR_dist_SD) ///
		title("a", position(11)) ///
		byopt(title("")) ///
		recast(line) ///
		recastci(rarea) ///
		xtitle(" ") ///
		ylabel(0(0.2)1, angle(0)) ///
		xlabel(0(0.5)2.5) ///
		ytitle("") ///
		plotregion(style(none) istyle(none)) ///
				addplot(scatter rug_where LR_dist_SD, ms(none) mlabel(rug_pipe) mlabpos(0) legend(order(2 "Preferred party" 1 "Other party" ))) ///
		xtitle("Policy position variance") ///
		ytitle("") ///
		legend(cols(2) position(6) region(style(none))) ///
			saving(EPSR_ipc_LR_PID, replace)

drop rug_*


* Interaktion regierungsbeteiligung_B parteineigung1_B
est restore m7

margins parteineigung1_B, at(regierungsbeteiligung_B=(0 1))

marginsplot ///
	, title("b", position(11)) ///
		xdimension(regierungsbeteiligung_B) ///
		plotopts(connect(none)) ///
		xtitle(" ") ///
		xlabel(-0.2 " " 0 "Opposition party" 1 "Governing party" 1.2 " ", notick) ///
		xsize(4) ///
		ylabel(0(0.2)1, angle(0)) ///
		ytitle("") ///
		plotregion(style(none) istyle(none)) ///
		xtitle("") ///
		ytitle("") ///
		legend(off) ///
			saving(EPSR_ipc_gov_PID, replace)


* Interaktion prox_BTW parteineigung1_B
est restore m8

su prox_BTW /// 
	if e(sample) == 1
local plot_prox_BTW_min = r(min)
local plot_prox_BTW_max = r(max)

gen rug_where = 0.02
gen rug_pipe = "|"
gen rug_sample = e(sample)
replace rug_pipe = "" ///
	if rug_sample == 0
sort rug_sample prox_BTW
replace rug_pipe = "" ///
	if prox_BTW == prox_BTW[_n-1]

margins parteineigung1_B, at(prox_BTW=(`plot_prox_BTW_min'(50)`plot_prox_BTW_max' `plot_prox_BTW_max'))

marginsplot ///
	, xdimension(prox_BTW) ///
		title("c", position(11)) ///
		byopt(title("")) ///
		recast(line) ///
		recastci(rarea) ///
		xtitle(" ") ///
		ylabel(0(0.2)1, angle(0)) ///
		xlabel(0(180)720) ///
		ytitle("") ///
		plotregion(style(none) istyle(none)) ///
				addplot(scatter rug_where prox_BTW, ms(none) mlabel(rug_pipe) mlabpos(0) legend(order(1 "Other party" 2 "Preferred party"))) ///
		xtitle("Distance to election") ///
		ytitle("") ///
		legend(off) ///
			saving(EPSR_ipc_prox_PID, replace)
		
drop rug_*


* Interaktion share_lost_elections parteineigung1_B
est restore m9

su share_lost_elections /// 
	if e(sample) == 1
local plot_share_lost_min = r(min)
local plot_share_lost_max = r(max)

gen rug_where = 0.02
gen rug_pipe = "|"
gen rug_sample = e(sample)
replace rug_pipe = "" ///
	if rug_sample == 0
sort rug_sample share_lost_elections
replace rug_pipe = "" ///
	if share_lost_elections == share_lost_elections[_n-1]

margins parteineigung1_B, at(share_lost_elections=(`plot_share_lost_min'(0.2)`plot_share_lost_max' `plot_share_lost_max'))

marginsplot ///
	, xdimension(share_lost_elections) ///
		title("d", position(11)) ///
		byopt(title("")) ///
		recast(line) ///
		recastci(rarea) ///
		xtitle(" ") ///
		ylabel(0(0.2)1, angle(0)) ///
		xlabel(0(0.25)1) ///
		ytitle("") ///
		plotregion(style(none) istyle(none)) ///
				addplot(scatter rug_where share_lost_elections, ms(none) mlabel(rug_pipe) mlabpos(0) legend(order(1 "Other party" 2 "Preferred party"))) ///
		xtitle("Share of lost elections") ///
		ytitle("") ///
		legend(off) ///
			saving(EPSR_ipc_lost_PID, replace)

drop rug_*


* Zusammenführen der Abbildungen
graph combine EPSR_ipc_LR_PID.gph EPSR_ipc_gov_PID.gph EPSR_ipc_prox_PID.gph EPSR_ipc_lost_PID.gph
graph export "$folder\EPSR_intra-party_conflict_Figure4.png", as(png) name("Graph") replace



exit
